/**
	Pulsar engine. Test cases.
	Additional include file.

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/


#define TC_ADD(cbFunc, count)          tc::TestSuite::_addTest(cbFunc, count, PL_T(#cbFunc))
#define TC_ADD_T(cbFunc, count, time)  tc::TestSuite::_addTest(cbFunc, count, #cbFunc, time)


/// TC_CHECK_MEM_LEAKS - define additional checkpoint to check memory leaks inside the test
#if defined(PL_MEMORY_DEBUG)
#define TC_CHECK_MEM_LEAKS()  tc::TestSuite::checkMemLeaks(PL_T(__FILE__), __LINE__, PL_T(__FUNCTION__))
#define TC_IGNORE_MEM_LEAKS() tc::TestSuite::ignoreMemLeaks()
#elif defined(PL_MEMORY_RELEASE) || defined (PL_MEMORY_FINAL)
#define TC_CHECK_MEM_LEAKS()  ((void)0)
#define TC_IGNORE_MEM_LEAKS() ((void)0)
#else
#error "Wrong debug memory configuration"
#endif
#define TC_IGNORE_THREAD_LEAKS() tc::TestSuite::ignoreThreadLeaks()
#define TC_CHECK_THREAD_LEAKS() tc::TestSuite::checkThreadLeaks(PL_T(__FILE__), __LINE__, PL_T(__FUNCTION__))

/// Show error message during test
#define TC_ERROR(msg)        do \
                                { \
                                    pl::String<1024> _msgStream_; \
                                    _msgStream_ << msg;\
                                    tc::TestSuite::errorMessage(_msgStream_.getStr(), PL_T(__FILE__), __LINE__, PL_T(__FUNCTION__)); \
                                } while(false)

/// Verify value and show error message
#define TC_VERIFY(expr)      do \
                                { \
                                    if (!(expr)) \
                                    {\
                                        TC_ERROR(PL_T("TC_VERIFY(") << PL_T(#expr) << PL_T(") failed")); \
                                    } \
                                } while(false)

#define TC_ENABLE_MEMORY_ERROR() tc::TestSuite::enableMemoryError(true)
#define TC_DISABLE_MEMORY_ERROR() tc::TestSuite::enableMemoryError(false)
#define TC_ENABLE_ALLOC_ERROR() tc::TestSuite::enableAllocError(true)
#define TC_DISABLE_ALLOC_ERROR() tc::TestSuite::enableAllocError(false)

#if defined(PL_DEBUG) || defined(PL_RELEASE)
/// Waiting for Assertion failed 
/// (use 0 - to disable conter)
#define TC_EXPECT_ASSERT(count)	tc::TestSuite::expectedAssert( count, PL_T(__FILE__), __LINE__, PL_T(__FUNCTION__ ))
#elif defined(PL_FINAL_GAME) || defined(PL_FINAL_TOOL)
#define TC_EXPECT_ASSERT(count)	((void)0)
#else
#error "Wrong build configuration"
#endif

/// Validate picture
#define TC_VERIFY_PICTURE(name) tc::TestSuite::verifyPicture(name)


//
// End of file 'testcase_rules.h'
//
